
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:qianyi/entity/home/trendVo.dart';
import 'package:qianyi/network/http_entity.dart';
import 'package:shared_preferences/shared_preferences.dart';

import '../../entity/profile/my_user_info_entity.dart';
import '../../network/base_entity.dart';
import '../../network/http_config.dart';
import '../../network/http_manager.dart';
import '../../ui/widget/custom_refresh_mixin.dart';
import '../../utils/navigator_util.dart';


class TrendViewModel extends ChangeNotifier with CustomRefreshMixin {

  TabController? tabController;




  @override
  Future<List> requestList(int page) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    Map<String,dynamic> userInfo = jsonDecode(prefs.getString("userInfo")!);


    Map<String, dynamic> params = {};
    params["uid"] = userInfo["id"];

    IBaseEntity? result = await HttpManager.getInstance().request(url: "/platform/follow/getAllFollowTrends/${page}/10",method: Method.get, params: params);
    HttpEntity httpEntity = result as HttpEntity;
    TrendEntityList trendEntityList = TrendEntityList.fromJson(httpEntity.oriData);
    List<String> imageIds = trendEntityList.getImageIds();
    Map<String,dynamic> params1 = {
      "imageIds": imageIds
    };

    HttpEntity httpEntity1 = await HttpManager.getInstance().request(url: "/platform/imgDetail/getCovers",method: Method.post,params: params1) as HttpEntity;
    List<String> returnImages = httpEntity1.getOriData()['data'].cast<String>();
    List<String> reversedImages = returnImages.reversed.toList();

    for (var i = 0; i < trendEntityList.trends!.length; i++) {
      trendEntityList.trends![i].cover = reversedImages[i];
    };
    if(this.datas.length > 50) {
      this.datas = this.datas.sublist(40);
      this.onLoading();

    }
    notifyListeners();

    return trendEntityList.trends!;
  }

  }
